home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / arphdr.c < prev    next >
C/C++ Source or Header  |  1991-02-25  |  2KB  |  66 lines

  1. /* @(#) $Header: arphdr.c,v 1.3 91/02/24 20:16:29 deyke Exp $ */
  2.  
  3. /* ARP header conversion routines
  4.  * Copyright 1991 Phil Karn, KA9Q
  5.  */
  6. #include "global.h"
  7. #include "mbuf.h"
  8. #include "arp.h"
  9.  
  10. /* Copy a host format arp structure into mbuf for transmission */
  11. struct mbuf *
  12. htonarp(arp)
  13. register struct arp *arp;
  14. {
  15.     struct mbuf *bp;
  16.     register char *buf;
  17.  
  18.     if(arp == (struct arp *)NULL)
  19.         return NULLBUF;
  20.  
  21.     if((bp = alloc_mbuf(ARPLEN + 2 * uchar(arp->hwalen))) == NULLBUF)
  22.         return NULLBUF;
  23.  
  24.     buf = bp->data;
  25.  
  26.     buf = put16(buf,arp->hardware);
  27.     buf = put16(buf,arp->protocol);
  28.     *buf++ = arp->hwalen;
  29.     *buf++ = arp->pralen;
  30.     buf = put16(buf,arp->opcode);
  31.     memcpy(buf,arp->shwaddr,(int16)uchar(arp->hwalen));
  32.     buf += arp->hwalen;
  33.     buf = put32(buf,arp->sprotaddr);
  34.     memcpy(buf,arp->thwaddr,(int16)uchar(arp->hwalen));
  35.     buf += arp->hwalen;
  36.     buf = put32(buf,arp->tprotaddr);
  37.  
  38.     bp->cnt = buf - bp->data;
  39.     return bp;
  40. }
  41. /* Convert an incoming ARP packet into a host-format structure */
  42. int
  43. ntoharp(arp,bpp)
  44. register struct arp *arp;
  45. struct mbuf **bpp;
  46. {
  47.     if(arp == (struct arp *)NULL || bpp == NULLBUFP)
  48.         return -1;
  49.  
  50.     arp->hardware = pull16(bpp);
  51.     arp->protocol = pull16(bpp);
  52.     arp->hwalen = PULLCHAR(bpp);
  53.     arp->pralen = PULLCHAR(bpp);
  54.     arp->opcode = pull16(bpp);
  55.     pullup(bpp,arp->shwaddr,(int16)uchar(arp->hwalen));
  56.     arp->sprotaddr = pull32(bpp);
  57.     pullup(bpp,arp->thwaddr,(int16)uchar(arp->hwalen));
  58.     arp->tprotaddr = pull32(bpp);
  59.  
  60.     /* Get rid of anything left over */
  61.     free_p(*bpp);
  62.     *bpp = NULLBUF;
  63.     return 0;
  64. }
  65.  
  66.